home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / parser.jar / com / sun / xml / parser / ContentModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-02-23  |  1.8 KB  |  113 lines

  1. package com.sun.xml.parser;
  2.  
  3. final class ContentModel {
  4.    public char type;
  5.    public Object content;
  6.    public ContentModel next;
  7.    private SimpleHashtable cache = new SimpleHashtable();
  8.  
  9.    public ContentModel(char var1, ContentModel var2) {
  10.       this.type = var1;
  11.       this.content = var2;
  12.    }
  13.  
  14.    public ContentModel(String var1) {
  15.       this.type = 0;
  16.       this.content = var1;
  17.    }
  18.  
  19.    public boolean empty() {
  20.       switch (this.type) {
  21.          case '\u0000':
  22.          case '+':
  23.             return false;
  24.          case '*':
  25.          case '?':
  26.             return true;
  27.          case ',':
  28.             if (!(this.content instanceof ContentModel)) {
  29.                return false;
  30.             } else if (!((ContentModel)this.content).empty()) {
  31.                return false;
  32.             } else {
  33.                for(ContentModel var2 = this.next; var2 != null; var2 = var2.next) {
  34.                   if (!var2.empty()) {
  35.                      return false;
  36.                   }
  37.                }
  38.  
  39.                return true;
  40.             }
  41.          case '|':
  42.             if (this.content instanceof ContentModel && ((ContentModel)this.content).empty()) {
  43.                return true;
  44.             } else {
  45.                for(ContentModel var1 = this.next; var1 != null; var1 = var1.next) {
  46.                   if (var1.empty()) {
  47.                      return true;
  48.                   }
  49.                }
  50.  
  51.                return false;
  52.             }
  53.          default:
  54.             throw new InternalError();
  55.       }
  56.    }
  57.  
  58.    public boolean first(String var1) {
  59.       Boolean var2 = (Boolean)this.cache.get(var1);
  60.       if (var2 != null) {
  61.          return var2;
  62.       } else {
  63.          boolean var3;
  64.          switch (this.type) {
  65.             case '\u0000':
  66.             case '*':
  67.             case '+':
  68.             case '?':
  69.                if (this.content instanceof String) {
  70.                   var3 = this.content == var1;
  71.                } else {
  72.                   var3 = ((ContentModel)this.content).first(var1);
  73.                }
  74.                break;
  75.             case ',':
  76.                if (this.content instanceof String) {
  77.                   var3 = this.content == var1;
  78.                } else if (((ContentModel)this.content).first(var1)) {
  79.                   var3 = true;
  80.                } else if (!((ContentModel)this.content).empty()) {
  81.                   var3 = false;
  82.                } else if (this.next != null) {
  83.                   var3 = this.next.first(var1);
  84.                } else {
  85.                   var3 = false;
  86.                }
  87.                break;
  88.             case '|':
  89.                if (this.content instanceof String && this.content == var1) {
  90.                   var3 = true;
  91.                } else if (((ContentModel)this.content).first(var1)) {
  92.                   var3 = true;
  93.                } else if (this.next != null) {
  94.                   var3 = this.next.first(var1);
  95.                } else {
  96.                   var3 = false;
  97.                }
  98.                break;
  99.             default:
  100.                throw new InternalError();
  101.          }
  102.  
  103.          if (var3) {
  104.             this.cache.put(var1, Boolean.TRUE);
  105.          } else {
  106.             this.cache.put(var1, Boolean.FALSE);
  107.          }
  108.  
  109.          return var3;
  110.       }
  111.    }
  112. }
  113.